﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Portal.API;
using Portal.Core.DAL;

namespace Portal.BO.Editoral.EditionType
{
    public class EditionTypeHelper
    {
        public static void Insert(string EditionName, string EditionDescription, string EditionDisplayURL)
        {
            using (MainDB db = new MainDB())
            {
                db.StoredProcedures.vc_EditionType_Insert(EditionName, EditionDescription, EditionDisplayURL);
            }
        }

        public static void Update(string EditionName, string EditionDescription, Int32 EditionType_ID, string EditionDisplayURL)
        {
            using (MainDB db = new MainDB())
            {
                db.StoredProcedures.vc_EditionType_Update(EditionName, EditionDescription, EditionType_ID, EditionDisplayURL);
            }
        }

        public static void Delete(Int32 EditionType_ID)
        {
            using (MainDB db = new MainDB())
            {
                db.StoredProcedures.vc_EditionType_Delete(EditionType_ID);

                db.SelectQuery("DELETE Category WHERE EditionType_ID = " + EditionType_ID.ToString());
            }
        }

        public static DataTable SelectOne(Int32 EditionType_ID)
        {
            using (MainDB db = new MainDB())
            {
                return db.StoredProcedures.vc_EditionType_SelectOne(EditionType_ID);
            }
        }

        public static DataTable SelectAll()
        {
            using (MainDB db = new MainDB())
            {
                DataTable table = db.StoredProcedures.vc_EditionType_SelectAll();
                if (table.Rows.Count == 0)
                {
                    DataRow dr = table.NewRow();
                    dr["EditionType_ID"] = 0;
                    dr["EditionName"] = String.Empty;
                    dr["EditionDescription"] = String.Empty;
                    table.Rows.Add(dr);
                }
                return table;
            }
        }

        public static DataTable SelectAllForDropdownlist()
        {
            using (MainDB db = new MainDB())
            {
                DataTable table = db.StoredProcedures.vc_EditionType_SelectAll();
                DataRow dr = table.NewRow();
                dr["EditionType_ID"] = 0;
                dr["EditionName"] = "-- Chọn loại --";
                table.Rows.InsertAt(dr, 0);

                return table;
            }
        }

        public static DataTable SelectAllForDropdownlist(DropDownList dl)
        {
            using (MainDB db = new MainDB())
            {
                DataTable table = db.StoredProcedures.vc_EditionType_SelectAll();
                //DataRow dr = table.NewRow();
                //dr["EditionType_ID"] = 0;
                //dr["EditionName"] = "-- Chọn loại --";
                //table.Rows.InsertAt(dr, 0);

                int RowCount = table.Rows.Count;
                for (int i = 0; i < RowCount; i++)
                {
                    dl.Items.Add(new ListItem(table.Rows[i]["EditionName"].ToString(), table.Rows[i]["EditionType_ID"].ToString()));
                }

                return table;
            }
        }
    }
}
